<!--
 * @Author: your name
 * @Date: 2022-03-30 14:30:19
 * @LastEditTime: 2022-03-30 15:20:02
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\不使用代理模式预加载图片220330.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>不使用代理模式预加载图片</title>
</head>

<body>
  <script>
    // 不使用代理的预加载图片函数如下
    var myImage = (function () {
      var imgNode = document.createElement("img");
      console.log(imgNode,"imgNode")
      document.body.appendChild(imgNode);
      var img = new Image();
      console.log(img,"img")
      img.onload = function () {
        imgNode.src = this.src;
      };
      return {
        setSrc: function (src) {
          console.log(imgNode,"imgNodetest")
          imgNode.src = "http://img.lanrentuku.com/img/allimg/1212/5-121204193Q9-50.gif";
          img.src = src;
        }
      }
    })();
    // 调用方式
    myImage.setSrc("https://img.alicdn.com/tps/i4/TB1b_neLXXXXXcoXFXXc8PZ9XXX-130-200.png");
  </script>
</body>

</html>